/*
    BibleNotebook - A bible reader software
    Copyright (C) 2014  Williams Fernando Lopez

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
 */
package com.simplebible.ui;

import java.awt.KeyEventDispatcher;
import java.awt.event.KeyEvent;
import com.simplebible.ui.components.MainPanel;

/**
 *
 * @author Williams Lopez
 */
public class KeyDispatcher implements KeyEventDispatcher {

    MainPanel mainPanel;

    public KeyDispatcher(MainPanel mainPanel) {
        this.mainPanel = mainPanel;
    }



    public boolean dispatchKeyEvent(KeyEvent e) {
        if (e.getID() == KeyEvent.KEY_PRESSED ){
            if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK) {
                String event = null;
                switch (e.getKeyCode()) {
                    case KeyEvent.VK_RIGHT: event = Events.NEXT_CHAPTER; break;
                    case KeyEvent.VK_LEFT:  event = Events.PREV_CHAPTER; break;
                    case KeyEvent.VK_G:     event = Events.SHOW_GENERAL_CONFIG; break;
                    case KeyEvent.VK_O:     event = Events.SHOW_SELECT_VERSE_PANEL; break;
                    //case KeyEvent.VK_B:     event = Events.SHOW_VERSION_CONFIG_PANEL; break;
                    case KeyEvent.VK_M:     event = Events.TOOGLE_BOOKMARK_PANEL; break;
                    case KeyEvent.VK_D:     event = Events.TOOGLE_DICTIONARY_PANEL; break;
                    case KeyEvent.VK_N:     event = Events.TOOGLE_NOTE_PANEL; break;
                    case KeyEvent.VK_P:     event = Events.TOOGLE_PARALLEL_VIEW; break;
                    case KeyEvent.VK_S:     event = Events.TOOGLE_SINCRONIZATION; break;
                }

                if(event!=null && mainPanel!=null){
                    Events.execute(event, mainPanel);
                }
            }
        }
        return false;
    }
}
